package main.util;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;

import main.iwith.Operator;

/**
 * Created by huilay on 2017/7/29.
 */

public class WebConn {

    public static String doGet(String url) throws IOException{
    	
    	//jsons="json2="+jsons;
        HttpURLConnection conn=null;
        URL realUrl = null;
        InputStream in=null;
        
        OutputStream out=null;
        try {
            //realUrl = new URL("http://101.200.36.6:8080/wxbook/addJSONFromAPP2.do");
        	realUrl = new URL(url);
            // 打开和URL之间的连接
            conn = (HttpURLConnection)realUrl.openConnection();
            // 设置通用的请求属性
            conn.setRequestProperty("accept", "*/*");
            conn.setRequestProperty("connection", "Keep-Alive");
            conn.setRequestProperty("user-agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36");
            conn.setRequestProperty("Content-Type","application/json");
            
            conn.setRequestMethod("GET");
            
            // 发送POST请求必须设置如下两行
            conn.setDoOutput(true);
            conn.setDoInput(true);
            //conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
            
            conn.setConnectTimeout(2000);
			conn.setReadTimeout(2000);
			//out.flush();
			
            // 定义BufferedReader输入流来读取URL的响应
            in = conn.getInputStream();
            
            byte[] b=new byte[in.available()];
            in.read(b);
            
            return new String(b);
        } catch (Exception e) {
        	System.out.println(e);
        }finally{
        	if(in!=null){
        		in.close();
        	}
        }
        
        return "";
    }
    
    public static void main(String[] args) throws IOException {
    	System.out.println(Operator.getIntend("加多宝"));
	}
}
